<?php
$config = 3*24*60*60;
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 98000));
if(isset($_REQUEST['url']))

{

function genhash ($url) {

	$hash = 'Mining PageRank is AGAINST GOOGLE\'S TERMS OF SERVICE. Yes, I\'m talking to you, scammer.';

	$c = 16909125;

	$length = strlen($url);

	$hashpieces = str_split($hash);

	$urlpieces = str_split($url);

	for ($d = 0; $d < $length; $d++) {

		$c = $c ^ (ord($hashpieces[$d]) ^ ord($urlpieces[$d]));

		$c = zerofill($c, 23) | $c << 9;

 	}

	return '8' . hexencode($c);

}



function zerofill($a, $b) {

	$z = hexdec(80000000);

  	if ($z & $a) {

  		$a = ($a>>1);

		$a &= (~$z);

		$a |= 0x40000000;

		$a = ($a>>($b-1));

	} else {

		$a = ($a>>$b);

	}

	return $a;

}



function hexencode($str) {

	$out  = hex8(zerofill($str, 24));

	$out .= hex8(zerofill($str, 16) & 255);

	$out .= hex8(zerofill($str, 8 ) & 255);

	$out .= hex8($str & 255);

	return $out;

}



function hex8 ($str) {

	$str = dechex($str);

	(strlen($str) == 1 ? $str = '0' . $str: null);

	return $str;

}



function getPageRank($url) {

	$googleurl = 'http://toolbarqueries.google.com/search?features=Rank&sourceid=navclient-ff&client=navclient-auto-ff&googleip=O;66.249.81.104;104&ch=' . genhash($url) . '&q=info:' . urlencode($url);

	if(function_exists('curl_init')) {

		$ch = curl_init();

		curl_setopt($ch, CURLOPT_HEADER, 0);

		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

		curl_setopt($ch, CURLOPT_URL, $googleurl);

		$out = curl_exec($ch);

		curl_close($ch);

	} else {

		$out = file_get_contents($googleurl);

	}

	return substr($out, 9);

}


include 'sdb.php';
$sdb = new simpledb("AKIAJQXQW644DKH7MGBA", "raYxoVwoUqolVLOMzc43cT+PRovnlWDg5jiOh8Ya");
$domainName="Domain";
	
$arr = $sdb->select($domainName,"select * from $domainName where domain ='{$_GET['url']}'");

if(!empty($arr) && (time() - $arr[0]['Attributes']['date']) < $config)
{
	$pr = $arr[0]['Attributes']['rank'];
} else {
	$pr = getPageRank($_REQUEST['url']);

	$sdb->putAttributes($domainName, $_REQUEST['url'], array("rank"=>array('value'=>$pr),"domain"=>array('value'=>$_REQUEST['url']),"date"=>array('value'=>time())),null,true);
}

if(isset($_REQUEST['f']))
{
	$f = $_REQUEST['f'];
} else {
	$f = 'image';
}

if($f == 'text')
{
	echo $pr;die;
}
if($f == 'xml')
{
	header("Content-type: text/xml");
	echo "<?xml version='1.0' encoding='ISO-8859-1'?>";
	echo "<pr>";
	echo $pr;
	echo "</pr>";
	die;
}
if($f == 'json')
{
	echo "{ \"url\":\"http://{$_REQUEST['url']}\" ,\"pagerank\":\"$pr\"}";die;
}

header("Content-type: image/gif");

switch($pr)

{

case 0:

header("Content-length: 272");

echo base64_decode(

'R0lGODlhRgAUAKIAAKSkpL+/v9zc3JSUlPT09AAAAISEhP///y'.

'H5BAAAAAAALAAAAABGABQAAAPVaLrc/jDK2Y69OOvN+zVep4Rk'.

'SYJUNR5FW5iZ+5Lzd6TMDbJWDfM9WgaFG61mL9nF1fPVkkxmEE'.

'hkAAgHAsCha7YwyGDY6+ONk7bGACvIDlS7sjSsnD6/56+lqggc'.

'AgZ+gDlHYHZiGk9AaItANzoLbVsABwJwU2RLelKOUHiHVJAKkg'.

'aUloQ7IWM/JXwGpKaXJXqsraKvB5OVsrW9IreCgX+8RcUTaVZZ'.

'AVhbqDa+vamuwhaDznvQ0chqAG9cK4/ZrNK3FF17xulc2Mbn4u'.

'KpP+rz9BMJADs='.

'');

break;

case 1:

    header("Content-length: 262");

    echo base64_decode(

'R0lGODlhRgAUAKIAAACZM6Wlpdzc3L29vZSUlAAAAISEhP///y'.

'H5BAAAAAAALAAAAABGABQAAAPLaLrc/jDK2Y69OOvN+zVep4Rk'.

'SYJUNR5FW5iZ+5Lzd6TMDbJWDfM9WgaFG61mL9nF1fPVkkxmEE'.

'h0CA4Bh67ZwiCDX66PF07aHgNLVrUbS7/K6bNb7lqqCgJmnTt6'.

'5WAaT0BmhEA3OgsBBwNXfAtbhyxSk0h2h1B0gFSJeQQGjlorIW'.

'E/JXgMoWwml6YnnalYojuutSKwC6p9tEW9E2cPupCjBgDGALY/'.

'vLgKwka8x8jJJsu+kTfR09TARde+3w/cONfa07TK4OnqEgkAOw'.

'=='.

'');

break;

case 2:

    header("Content-length: 271");

    echo base64_decode(

'R0lGODlhRgAUAKIAAN3d3b6+vqmpqZeXlwCZMwAAAISEhP///y'.

'H5BAAAAAAALAAAAABGABQAAAPUaLrc/jDK2Y69OOvN+zVep4Rk'.

'SYJUNR5FW5iZ+5Lzd6TMDbJWDfM9WgaFG61mL9nF1fPVkkxmEE'.

'hkCACWgEPXbGGQQXDXxxMnbY2BBXvQ5o4xLxAqny+95npVETgA'.

'DAJ+KjtOU2BkQGVhhol7CgMDgIJvhF9SLHKXT5h4jFQ6D1gCgy'.

'ViPyWOj1hulCZ1pyegDKsPXLC3Hqm0tSuyRb+1Fo59GH+twgTJ'.

'ygS4qGizGcYLtjfLys2xwr4U1AbWydghOzfbE93A6FvawNTh2O'.

'M/6fLzEwkAOw=='.

'');

break;

case 3:

    header("Content-length: 274");

    echo base64_decode(

'R0lGODlhRgAUAKIAAKqqqr+/v5iYmObm5gCZMwAAAISEhP///y'.

'H5BAAAAAAALAAAAABGABQAAAPXaLrc/jDK2Y69OOvN+zVep4Rk'.

'SYJUNR5FW5iZ+5Lzd6TMDbJWDfM9WgaFG61mL9nF1fPVkkxmEE'.

'hkAAaHgcCha7YwyGDY6+ONk7aGwILV5Y6xLxAqny+/53pVcQ0Y'.

'sAAqO05TYWVAZmKFiHsNWFxwd3VSUoh0aHZUbhUHgYIlYz8ljQ'.

'sBWFtvOzSHoiKbDQBZn620Ho0BB36xA7OvRb9cFrcWuJ29BgTJ'.

'ysvJtRyqpMW5kNDM1gTOG9C+BgIAqMfXzNka28BdwsDqwTfcEu'.

'jk5Ko/6/X2EwkAOw=='.

'');

break;

case 4:

    header("Content-length: 265");

    echo base64_decode(

'R0lGODlhRgAUAKIAAJmZmdvb26+vr/f39wCZMwAAAISEhP///y'.

'H5BAAAAAAALAAAAABGABQAAAPOaLrc/jDK2Y69OOvN+zVep4Rk'.

'SYJUNR5FW5iZ+5Lzd6TMDbJWDfM9WgaFG61mL9nF1fPVkkxmEE'.

'h8BAIOXbOFQQa9Wx8PnLRBApbsMcYFQtvuJZcMrzIEH9XOOfWK'.

'gWNffYB2CgADaDo5a3JwUlKAb2VxVIoLAQM7ajshYD8lhXgCmn'.

'omcJ8nljtXFgEAi5yoshyFG6MLWmlFuxJmELqwHwTDxMXGBLMY'.

'nIU5qkTCx9HDyTZpzhO5N9LS1NbWvNm84g++Rdnd1LEw4+ztEw'.

'kAOw=='.

'');

break;

case 5:

    header("Content-length: 271");

    echo base64_decode(

'R0lGODlhRgAUAKIAAOvr69jY2JeXl7GxsQCZMwAAAISEhP///y'.

'H5BAAAAAAALAAAAABGABQAAAPUaLrc/jDK2Y69OOvN+zVep4Rk'.

'SYJUNR5FW5iZ+5Lzd6TMDbJWDfM9WgaFG61mL9nF1fPVkkxmEE'.

'hkDALYwEC1Uy6nySlL+kUGa9VFALPNHWMt8Dgub4aB5LQCcBgI'.

'/FxieHI+YneHZzYOBwB/DzqCXnN2X2dRdTN6AxiNgUJAPyWajA'.

'N8AZ40haEeegYCAiuoq7Mco20WqEW6E4pWFqUHp247NwTGx8jJ'.

'ybTErWsWwsMfytTUzL0Nf7CLK8XV38bXuDpFkLi76Ivju+a07k'.

'Oz6fLzEwkAOw=='.

'');

break;

case 6:

    header("Content-length: 281");

    echo base64_decode(

'R0lGODlhRgAUAKIAALu7u6mpqZiYmNra2gCZMwAAAISEhP///y'.

'H5BAAAAAAALAAAAABGABQAAAPeaLrc/jDK2Y69OOvN+zVep4Rk'.

'SYJUNR5FW5iZ+5Lzd6TMDbJWDfM9WgaFG61mL9nF1fPVkkxmEE'.

'hkCAYWgEPXbGGQQXDXxxMnbdsD9iBQ7chSsHL69Jq9lqoCcNAC'.

'BgFuU3SEZEBlYYVoDFgBAW1bR19SLHiUT5V2hFQ6C2sWA5E7IW'.

'I/JXoGWAN8fYIleKannQqNBgFqrrG6IrMGfIG3oTkrvUXGaTe9'.

'AllZuQYE0NHS09TRP6OovhfCw9jV3+DXiw6PD1x54OnT4nnFE+'.

'fux/LjOPC79xij1/L8/SkJADs='.

'');

break;

case 7:

    header("Content-length: 265");

    echo base64_decode(

'R0lGODlhRgAUAKIAAKioqMDAwODg4JqamgCZMwAAAISEhP///y'.

'H5BAAAAAAALAAAAABGABQAAAPOaLrc/jDK2Y69OOvN+zVep4Rk'.

'SYJUNR5FW5iZ+5Lzd6TMDbJWDfM9WgaFG61mL9nF1fPVkkxmEE'.

'hcBARYbEC1Uy6nySlL+kUGa1WFICPgiptmnhf4bNHhtsYAwF8P'.

'3EBggj5iYXKDeQ8AB1uATmRSkGVRglQ6DmsPOiVxPyVpVoyaKz'.

'SEnh6gapeAp60iqwoDB22jO7BFuA6JDIuNuqQGBMLDxMXGxp+7'.

'ob6swcfP0MLJFqkTm9TR2cgnyinXt7nhttUS367nGLY/4uztEw'.

'kAOw=='.

'');

break;

case 8:

    header("Content-length: 283");

    echo base64_decode(

'R0lGODlhRgAUAKIAANbW1uvr66CgoLm5uQCZMwAAAISEhP///y'.

'H5BAAAAAAALAAAAABGABQAAAPgaLrc/jDK2Y69OOvN+zVep4Rk'.

'SYJUNR5FW5iZ+5Lzd6TMDbJWDfM9WgaFG61mL9nF1fPVkkxmEE'.

'hkDAKHwMCha7YwyGDY6+ONk7aGwDKwCFS7sjSsnD6/56+lqmhv'.

'/XBTdoNlQGZihGkMawAGAAdvOUdgUix6lU+WeINUOlYXW4FChj'.

'8nngprB22QojSFpSKnjqyMrbC3HHyzW7WSO7JFwVx7sm0BAlih'.

'C117BM7P0NHS09C5igyPFo2tBtTe39HWxA8C5Q/MN+Dq3uI3wB'.

'PowvLn48HouPgYvz/z/f4TCQAAOw=='.

'');

break;

case 9:

    header("Content-length: 284");

    echo base64_decode(

'R0lGODlhRgAUAKIAAPX19bm5uZ+fn9ra2gCZMwAAAISEhP///y'.

'H5BAAAAAAALAAAAABGABQAAAPhaLrc/jDK2Y69OOvN+zVep4Rk'.

'SYJUNR5FW5iZ+5Lzd6TMDbJWDfM9WgaFG61mL9nF1fPVkkxmEE'.

'hkBACHgcCha7YwyGDY6+ONk7ZGwDI4ALjH2BcIndOX37O9qmgH'.

'DGt/OXFLU2FlQGZihol8Bm1bAlkqO05SLHOXT5h5jFQ6C2tabQ'.

'OUJWM/JY4GWG6Tgzs0iKkioFYBoqa0ux6OAgFbgbq2RcUPaVZu'.

'VwdbsB8E0NHS09TV1hixq23KcNnW3+Df2MgNAs3dz+Hq6uMWqx'.

'Nd7sbzXO7EFPG8+kO79P7/ExIAADs='.

'');

break;

case 10:

    header("Content-length: 289");

    echo base64_decode(

'R0lGODlhSAAWALMAAAAAAP///wCZM/f39+zs7OHh4dPT08zMzMDAwLW1taqqqpmZmYmJiYSEhP///wAAACH5BAEAAA4ALAAAAABIABYAAAT/MMhJq704632b/2AojmRpnqDUcGybre4Ew3HNrmgYzBLgA7bAD8ghyna5z07Va9qMxkx0mVTyhM3h5NeLQoVcrpOI+xwYoAPBgPYs39rtGEsH+ypAor5ebhgCCx8EAQiDVkx1XXtYcXRQd4tiVAwDA4AeDEgrCW5XXnOMFl97kXw7CgorgQ0JA2YFnYhekmK0clqldH2qHoUfvjiIG4tBGruXDcDJBLFvRVPFHZq8y7/Mwc7R2kwpqwuaAwjNNFXlJ0fdSgULCJpv5ALx8vP09fb38+TTyA2UEqnjZOAbSHCgPnPvBBZcyPBguYQqzEkUge7hlW3baMSYMbGjxxIYBENijAAAOw==');

break;

}

return;

}

?>
